文章目录
  1. 1. 题目
  2. 2. 解答
    1. 2.1. C语言实现
    2. 2.2. C++实现
    3. 2.3. Java实现

题目

杭电acm题目:http://acm.hdu.edu.cn/showproblem.php?pid=1000

解答

以下为在杭电hdu acm上已AC的C语言、C++和Java实现的三种方法

C语言实现

1
2
3
4
5
6
7
8
9
10
#include <stdio.h>
void main()
{
int a,b,sum;
while(scanf ("%d %d",&a,&b)!=EOF)
{
sum=a+b;
printf ("%d\n",sum);
}
}

C++实现

1
2
3
4
5
6
7
8
9
#include<iostream>
using namespace std;
int main()
{
int a,b;
while(cin>>a>>b)
cout<<a+b<<endl;
return 0;
}

Java实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
int a,b,sum;
Scanner scanner=new Scanner(System.in);
while(scanner.hasNext()){
a=scanner.nextInt();
b=scanner.nextInt();
sum=a+b;
System.out.println(a+b);
}
}
}
文章目录
  1. 1. 题目
  2. 2. 解答
    1. 2.1. C语言实现
    2. 2.2. C++实现
    3. 2.3. Java实现